package com.it.jzs.config;

import com.it.jzs.handle.AuthInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Override  // 资源映射
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //上传的图片在D盘下的OTA目录下，访问路径如：http://localhost:8081/OTA/d3cf0281-bb7f-40e0-ab77-406db95ccf2c.jpg
        //其中OTA表示访问的前缀。"file:D:/OTA/"是文件真实的存储路径
        registry.addResourceHandler("/upload01/**").addResourceLocations("file:E:/upload01/");
        registry.addResourceHandler("/upload02/**").addResourceLocations("file:E:/upload02/");
//        registry.addResourceHandler("/")
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/type/upload").excludePathPatterns("/admin/tag/upload")
                .addPathPatterns("/comment/**");
                // comment 为了删除threadlocal
        // 拦截关于后台的接口，但对于前台的数据展示不需要拦截
    }
}